package com.example.hutudshelf.security;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RequiredArgsConstructor
public class MyUserDetailsSercie implements UserDetailsService {


    /**
     *
     *
     * @author              xiaohu0305
     * @param username      security中输入的用户名
     * @time                2025-4-18
     * @return              org.springframework.security.core.userdetails.UserDetails
     */
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        log.info("拿到的username为: {}, 模拟进行数据库操作! 查询到用户名为: htd 密码为 123", username);
        if (username.equals("htd")){
            return new MyUserDetails(null, "htd",new BCryptPasswordEncoder().encode("123"), true, true, true, true);
        }
        return null;
    }
}
